home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / FALCON / ACC / OUTLINE.ACC / FSMIO.C2 < prev    next >
Encoding:
Text File  |  2001-02-10  |  30.9 KB  |  1,244 lines

  1. /* FILE: FSMIO.C
  2.  * ====================================================================
  3.  * Handles the disk I/O for the FONTS DA
  4.  *
  5.  * DATE CREATED: January 4, 1990  k. soohoo
  6.  *         December 7, 1992 c.gee - Still not shipped...
  7.  *         December 15, 1992 Remove Bitmap and Devices
  8.  */
  9.  
  10.  
  11. /* INCLUDE FILES
  12.  * ====================================================================
  13.  */
  14. #include <sys\gemskel.h>
  15.  
  16. #include "country.h" 
  17. #include "fonthead.h"
  18. #include "text.h"
  19. #include "extend.h"
  20. #include "spdhead.h"
  21. #include "front.h"
  22.  
  23.  
  24.  
  25. /* DEFINES
  26.  * ====================================================================
  27.  */
  28. #define ACTIVE        0
  29. #define INACTIVE    1
  30.  
  31.  
  32.  
  33.  
  34. /* Structure to store the global variables required for EXTEND.SYS */
  35. typedef struct fsm
  36. {
  37.    char FontPath[ 128 ];    /* Font Directory Path             */
  38.    long SpeedoCacheSize;    /* Speedo Cache Size           */
  39.    long BitMapCacheSize;    /* BITmap Cache Size           */
  40.    int  speedo_percent;        /* Percentage (1-9) for fsm cache  */
  41.    int  Width;            /* Width Tables?           */
  42.    int  point_size[ MAX_POINTS ]; /* Point Sizes of Current font  */
  43. }XFSM;
  44.  
  45.  
  46.  
  47. /* PROTOTYPES
  48.  * ====================================================================
  49.  */
  50. void     GetExtendSysPath( void );
  51.  
  52. char    GetBaseDrive( void );
  53. long    GetBootDrive( void );
  54.  
  55. #if 0
  56. char    *extract_path( int *offset, int max );
  57. int     kisspace( char thing );
  58. #endif
  59.  
  60. void     read_fonts( int flag, int flag2 );
  61.  
  62. void    ReadOutlineFonts( int flag );
  63. void    ReadUnUsedOutlineFonts( void );
  64. FON_PTR get_single_fsm_font( char *fontname );
  65.  
  66. void    free_arena_links( void );
  67. void    free_all_fonts( void );
  68.  
  69. FON_PTR another_font( int flag );
  70. void    Delete_Font( FON_PTR nodeptr );
  71. FON_PTR find_font_in_arena( char *userstring, char *extension );
  72. int    build_list( FON_PTR *top_list, FON_PTR *top_last, int type );
  73. void     alpha_font_add( FON_PTR *top_list, FON_PTR *top_last, FON_PTR font);
  74.  
  75. #if 0
  76. int    build_specific_list( FON_PTR *top_list, FON_PTR *top_last, int type );
  77. #endif
  78.  
  79. int    CountFonts( FON_PTR head_list, int flag );
  80. int    CountSelectedFonts( FON_PTR head_list, int flag );
  81.  
  82.  
  83. void    set_font_pts( FON_PTR font, char points[]);
  84. void    CheckForDefaultPointSizes( void );
  85.  
  86. long    GetFontMin( void );
  87. long    GetCharMin( void );
  88.  
  89.  
  90. int    fast_write_extend( void );
  91. int     write_extend( void );
  92. void    write_pointsizes( FON_PTR font, int new_extend);
  93.  
  94.  
  95.  
  96.  
  97. /* EXTERNS
  98.  * ====================================================================
  99.  */
  100.  
  101.  
  102. /* GLOBALS
  103.  * ====================================================================
  104.  */
  105. DTA *olddma, newdma;            /* DTA buffers for _our_ searches */
  106. char *bufptr;                /* ptr to malloc'ed memory...     */
  107. long BufferSize;            /* Size of ASSIGN.SYS/EXTEND.SYS  */
  108. char baddata[80];            /* String area for form_alerts.  */
  109. char line_buf[80];
  110.  
  111. char ExtendPath[20];            /* Path of EXTEND.SYS          */
  112. char OldExtendPath[20];                /* Path of EXTEND.OLD          */
  113. char OutlinePath[128];            /* Path of Outline Fonts          */
  114.  
  115. int  outline_found;            /* TRUE for found paths to outline*/
  116. int  alen;                /* # bytes we read               */
  117. int  BootDrive;                  /* Boot Device - 'A' or 'C' */
  118. char SearchPath[128];            /* TempSearchStrings        */
  119. char TempPath[128];            /* TempSearchStrings    */
  120.  
  121. FON     font_arena[ MAX_FONTS ];         /* We use a static arena         */
  122. int     free_font[ MAX_FONTS ];             /* Keeps track of what's open    */
  123. int     font_counter = 0;             /* # of fonts loaded available   */
  124. int     available_count, installed_count;/* # of active/inactive fonts    */
  125. FON_PTR available_list, installed_list;  /* Linked list pointers to the   */
  126. FON_PTR available_last, installed_last;  /* active/inactive fonts.        */
  127. int     Fonts_Loaded;             /* Unused Fonts Loaded or not... */
  128.  
  129. XFSM Current;            /* Current EXTEND.SYS variables */
  130. XFSM Backup;            /* Backup EXTEND.SYS variables  */
  131.  
  132.  
  133.  
  134. /* FUNCTIONS
  135.  * ====================================================================
  136.  */
  137.  
  138.  
  139.  
  140. /* GetExtendSysPath()
  141.  * ====================================================================
  142.  * Get the font path from the EXTEND.SYS
  143.  * If there is NO EXTEND.SYS, we substitute C: or A: instead.
  144.  *
  145.  */
  146. void 
  147. GetExtendSysPath( void )
  148. {
  149.     char *fname;
  150.     int  status;
  151.  
  152.     /* Get the Path to the EXTEND.SYS, EXTEND.OLD and the Outline path*/
  153.     strcpy( ExtendPath, "C:\\EXTEND.SYS" );
  154.     strcpy( OldExtendPath, "C:\\EXTEND.OLD" );
  155.     strcpy( OutlinePath, "C:" );
  156.     ExtendPath[0] = OldExtendPath[0] = OutlinePath[0] = GetBaseDrive();
  157.     status = GetSYSPath( ExtendPath, &OutlinePath[0] );
  158.     outline_found = (( status ) ? ( FALSE ) : ( TRUE ) );
  159.     
  160.     /* Convert to Upper Case */
  161.     fname = &OutlinePath[0];
  162.     fname = strupr( fname );
  163. }
  164.  
  165.  
  166.  
  167.  
  168. /* GetBaseDrive()
  169.  * ====================================================================
  170.  * Get the A drive or C drive for the ASSIGN.SYS and EXTEND.SYS
  171.  * based upon the boot drive.
  172.  */
  173. char
  174. GetBaseDrive( void )
  175. {
  176.     char Drive;
  177.  
  178.     Supexec( GetBootDrive );
  179.     Drive = BootDrive + 'A';    
  180.     return( Drive );
  181. }
  182.  
  183.  
  184.  
  185. /* GetBootDrive()
  186.  * ====================================================================
  187.  */
  188. long
  189. GetBootDrive( void )
  190. {
  191.    int *ptr;
  192.    
  193.    ptr = ( int *)0x446L;
  194.    BootDrive = *ptr;
  195.    return( 0L );
  196. }
  197.  
  198.  
  199. #if 0 
  200. /* extract_path()
  201.  * ====================================================================
  202.  *  Given an index into bufptr, immediately following the keyword that
  203.  *  indicates a path follows, will extract a pointer to the path and
  204.  *  return it.
  205.  */
  206. char
  207. *extract_path( int *offset, int max )
  208. {
  209.     int j;
  210.  
  211.     /* Goes looking for the start of the path */
  212.     while ( ( bufptr[ *offset ] != '=' ) && ( *offset < max ) )
  213.     {
  214.       *offset += 1;
  215.     }
  216.     
  217.     *offset += 1;
  218.     while ( ( kisspace(bufptr[*offset])) && ( *offset < max) )
  219.     {
  220.       *offset += 1;
  221.     }
  222.  
  223.     /* Properly null terminates the path */
  224.     j = *offset;
  225.     while ((bufptr[j] != '\n') && (j < (max - 1)) && (bufptr[j] != '\r')) {++j;}
  226.     bufptr[j] = '\0';
  227.  
  228.     return ( &bufptr[*offset] );
  229. }
  230.  
  231.  
  232. /* kisspace()
  233.  * ====================================================================
  234.  */
  235. int 
  236. kisspace( char thing )
  237. {
  238.     if ((thing == ' ') || (thing == '\t')) return TRUE;
  239.     else return FALSE;
  240. }
  241.  
  242. #endif
  243.  
  244.  
  245. /* read_fonts()
  246.  * ====================================================================
  247.  * Reads in the OUtline fronts and inserts them into the list.
  248.  * NOTE: We are reading in only the fonts used in the
  249.  * EXTEND.SYS unless otherwise noted.
  250.  * flag == 0 -> read in only the extend.sys
  251.  * flag == 1 -> read in the unused fonts.
  252.  *
  253.  * flag2 == 0 -> read in the extend.sys file and don't preserve Current.
  254.  * flag2 == 1 -> read in the extend.sys file and preserve the Current.
  255.  * Only when the flag is set do we read in ALL of the fonts.
  256.  * Returns a 0 on file error.
  257.  */
  258. void 
  259. read_fonts( int flag, int flag2 )
  260. {
  261.     /* READ the EXTEND.SYS fonts...*/
  262.         if( !flag )
  263.         {
  264.        free_all_fonts();
  265.        ReadOutlineFonts( flag2 );
  266.        CheckForDefaultPointSizes();
  267.        Fonts_Loaded = FALSE;
  268.     }
  269.     else
  270.     {
  271.        /* Clear the linked list pointers */
  272.        free_arena_links();
  273.  
  274.        /* READ the UNUSED OUTLINE FONTS */
  275.        ReadUnUsedOutlineFonts();
  276.         Fonts_Loaded = TRUE;
  277.     }  
  278.     
  279.     /* Create 2 linked lists from the static array -
  280.      * One is the Installed Fonts linked list.
  281.      * and the other is the Available Fonts linked list.
  282.      */
  283.     installed_count = build_list( &installed_list, &installed_last, ACTIVE );
  284.     available_count = build_list( &available_list, &available_last, INACTIVE );
  285. }
  286.  
  287.  
  288.  
  289. /* --------------------------------------------------------------------
  290.  * OUTLINE FONT SECTION
  291.  * ====================================================================
  292.  */
  293.  
  294.  
  295.  
  296. /* ReadOutlineFonts()
  297.  * ====================================================================
  298.  * Read in the outline fonts fromthe extend.sys
  299.  * flag == 0 read in and init the Current variables.
  300.  * flag == 1 read in the fonts fromthe extend.sys only.
  301.  *         Do not touch the Current Variables.
  302.  */
  303. void
  304. ReadOutlineFonts( int flag )
  305. {
  306.     parse_extend( flag );
  307. }
  308.  
  309.  
  310.  
  311.  
  312.  
  313. /* ReadUnUsedOutlineFonts()
  314.  * ====================================================================
  315.  */
  316. void
  317. ReadUnUsedOutlineFonts( void )
  318. {
  319.     int     fd, i, error;
  320.     char    nlen;
  321.     FON_PTR temp_fon;
  322.         SPDHDR  Header;
  323.  
  324.     olddma = Fgetdta();    
  325.     Fsetdta( &newdma );        /* Point to OUR buffer */
  326.  
  327.     sprintf( SearchPath, "%s\\%s", OutlinePath, "*.SPD" );
  328.     error = Fsfirst( SearchPath, 0 );/* Normal file search for 1st file */
  329.     if( error != E_OK )    /* No such files! */
  330.     {
  331.        Fsetdta( olddma );    /* Point to OLD buffer */
  332.        return;        
  333.     }
  334.  
  335.     do
  336.     {
  337.        temp_fon = another_font( SPD_FONT );
  338.        if (temp_fon == (FON_PTR) NULL)
  339.        {
  340.          Fsetdta(olddma);    /* Point to OLD buffer */
  341.          return;
  342.        }
  343.         
  344.        sprintf( FFNAME( temp_fon ),"%s", (char *)newdma.d_fname );
  345.        sprintf( TempPath,"%s\\%s", OutlinePath, FFNAME( temp_fon ) );
  346.        fd = Fopen( TempPath, 0 );/* Open the file */
  347.  
  348.        if( fd < 0 )    /* Bad open */
  349.        {
  350. #if 0       
  351.          sprintf( baddata, alert6, FFNAME( temp_fon ) );
  352. /*         form_alert( 1, baddata );   */
  353. #endif
  354.              Delete_Font( temp_fon );
  355.          goto recover;
  356.        }
  357.  
  358.            if( Fread( fd, sizeof( SPDHDR ), &Header ) < 0 )
  359.            {
  360.           Fclose( fd );
  361. /*          
  362.           sprintf( baddata, alert6, FFNAME( temp_fon ) );
  363.  */          
  364.           goto recover;
  365.            }
  366.  
  367.        FONTID( temp_fon ) = Header.FontID;
  368.            strcpy( FNAME( temp_fon ), &Header.ShortFontName[0] );
  369.  
  370.        FBUFF_SIZE( temp_fon ) = Header.MinFontBuffSize;
  371.        CBUFF_SIZE( temp_fon ) = Header.MinCharBuffSize;
  372.         
  373.        strncpy( FNAME( temp_fon ), &Header.ShortFontName[0], FRONT_LENGTH );
  374.        nlen = strlen( FNAME( temp_fon ) );
  375.        for( i = ( int )nlen; i < FRONT_LENGTH; ++i )
  376.             FNAME(temp_fon)[i] = ' ';
  377.        FNAME( temp_fon )[FRONT_LENGTH] = '\0';
  378.  
  379.        SEL( temp_fon ) = FALSE;
  380.        for( i = 0; i < MAX_POINTS; ++i )
  381.           POINTS( temp_fon )[i] = (int)NULL;
  382.        POINTS( temp_fon )[0] = 10;    /* Default point sizes for InActiveFonts */
  383.  
  384.        Fclose( fd );
  385.        /* Make sure the font hasn't already been loaded. */
  386.        if( find_font_in_arena( FFNAME( temp_fon ), ".SPD" ))
  387.        {
  388.          Delete_Font( temp_fon );
  389.          goto recover;
  390.        }  
  391.        font_counter++;        /* increment # of fonts available*/
  392. recover:;
  393.  
  394.     } while( Fsnext() == E_OK );
  395.     Fsetdta( olddma );    /* Point to OLD buffer */
  396. }
  397.  
  398.  
  399.  
  400.  
  401. /* get_single_fsm_font()
  402.  * ====================================================================
  403.  * Reads the FSM fonts into the arena and alphabetizes them.
  404.  * RETURNS: Pointer to font in font list.
  405.  *          NULL otherwise.
  406.  */
  407. FON_PTR
  408. get_single_fsm_font( char *fontname )
  409. {
  410.     int     fd, i, error;
  411.     char    nlen;
  412.     FON_PTR temp_fon;
  413.         SPDHDR  Header;
  414.  
  415.     olddma = Fgetdta();    
  416.     Fsetdta( &newdma );        /* Point to OUR buffer */
  417.  
  418.     sprintf( SearchPath, "%s\\%s%s", OutlinePath, fontname, ".SPD" );
  419.     error = Fsfirst( SearchPath, 0 );/* Normal file search for 1st file */
  420.     if( error != E_OK )    /* No such files! */
  421.     {
  422.        Fsetdta( olddma );    /* Point to OLD buffer */
  423.        return( ( FON_PTR )NULL );        
  424.     }
  425.     
  426.         /* Try to get a slot within the font list.
  427.          * return if the place is full. NO VACANCY
  428.          */ 
  429.     temp_fon = another_font( SPD_FONT );
  430.     if (temp_fon == (FON_PTR)NULL)
  431.     {
  432. /*      form_alert(1, alert12);*/
  433.       Fsetdta(olddma);    /* Point to OLD buffer */
  434.       return( ( FON_PTR )NULL );
  435.     }
  436.     fd = Fopen( SearchPath, 0 );/* Open the file */
  437.  
  438.     if( fd < 0 )    /* Bad open */
  439.     {
  440. /*    
  441.       sprintf( baddata, alert6, FFNAME( temp_fon ) );
  442. */      
  443.       goto recover;
  444.     }
  445.  
  446.  
  447.         if( Fread( fd, sizeof( SPDHDR ), &Header ) < 0 )
  448.         {
  449.        Fclose( fd );
  450. /*       
  451.        sprintf( baddata, alert6, FFNAME( temp_fon ) );
  452.  */       
  453.        goto recover;
  454.         }
  455.         
  456.         sprintf( FFNAME( temp_fon ),"%s", (char *)newdma.d_fname );
  457.     FONTID( temp_fon ) = Header.FontID;
  458.     FBUFF_SIZE( temp_fon ) = Header.MinFontBuffSize;
  459.     CBUFF_SIZE( temp_fon ) = Header.MinCharBuffSize;
  460.  
  461.     strncpy( FNAME( temp_fon ), &Header.ShortFontName[0], FRONT_LENGTH );
  462.     nlen = strlen( FNAME( temp_fon ) );
  463.     for( i = ( int )nlen; i < FRONT_LENGTH; ++i )
  464.        FNAME(temp_fon)[i] = ' ';
  465.     FNAME( temp_fon )[FRONT_LENGTH] = '\0';
  466.  
  467.         /* Initialize the Point Sizes nothingness...*/
  468.     for( i = 0; i < MAX_POINTS; ++i )
  469.        POINTS( temp_fon )[i] = (int)NULL;
  470.     Fclose( fd );
  471.  
  472.     /* Check if the font already is installed.*/
  473.     if( find_font_in_arena( FFNAME( temp_fon ), ".SPD" ))
  474.          goto recover;
  475.  
  476.     SEL( temp_fon ) = TRUE;        /* Set to INSTALLED */
  477.     font_counter++;            /* increment# of fonts available*/  
  478.  
  479.     Fsetdta( olddma );    /* Point to OLD buffer */
  480.     return( temp_fon );
  481.  
  482. recover:;/* Problem with reading the file...*/
  483. /*    form_alert( 1, baddata );*/
  484.         Delete_Font( temp_fon );
  485.     Fsetdta( olddma );    /* Point to OLD buffer */
  486.     return( ( FON_PTR )NULL );
  487. }
  488.  
  489.  
  490.  
  491.  
  492. /* --------------------------------------------------------------------
  493.  * FONT HANDLING SECTION
  494.  * ====================================================================
  495.  */
  496.  
  497. /* free_arena_links()
  498.  * ====================================================================
  499.  * Free up the linked list pointers in the font arena.
  500.  * Used when we move fonts between installed and available.
  501.  */
  502. void
  503. free_arena_links( void )
  504. {
  505.    FON_PTR curptr;
  506.    int i;
  507.       
  508.    for( i = 0; i < MAX_FONTS; i++ )
  509.    {
  510.        curptr = &font_arena[i];
  511.        FNEXT( curptr ) = FPREV( curptr ) = ( FON_PTR )NULL;
  512.        AFLAG( curptr ) = SFLAG( curptr ) = FALSE;
  513.    }
  514.    installed_list = installed_last = ( FON_PTR )NULL;
  515.    available_list = available_last = ( FON_PTR )NULL;
  516.    installed_count = available_count = 0;
  517. }
  518.  
  519.  
  520.  
  521. /* free_all_fonts()
  522.  * ====================================================================
  523.  * Responsible for resetting all the font parameters to something
  524.  * normal, as well as freeing up all the arena space it's been using.
  525.  * Caller is responsible for re-calling the font reading routines.
  526.  */
  527. void
  528. free_all_fonts( void )
  529. {
  530.     int i;
  531.     FON_PTR curptr;
  532.         
  533.     for (i = 0; i < MAX_FONTS; ++i)
  534.     {
  535.        /* Free arena space */
  536.        if( !free_font[i] )
  537.         free_font[i] = TRUE;
  538.        curptr = &font_arena[i];
  539. /* NOTE - this is not a complete wipe */       
  540.        FNEXT( curptr ) = FPREV( curptr ) = ( FON_PTR )NULL;    
  541.     }
  542.  
  543.     available_list  = ( FON_PTR )NULL;
  544.     available_last  = ( FON_PTR )NULL;
  545.     available_count = 0;
  546.  
  547.     installed_list  = ( FON_PTR )NULL;
  548.     installed_last  = ( FON_PTR )NULL;
  549.     installed_count = 0;
  550.  
  551.     font_counter    = 0;
  552. }
  553.  
  554.  
  555.  
  556. /* another_font()
  557.  * ====================================================================
  558.  */
  559. FON_PTR
  560. another_font( int flag )
  561. {
  562.  
  563.     FON_PTR newfont;
  564.     int i;
  565.  
  566.     /* If there are way too many fonts...*/
  567.     if( font_counter >= MAX_FONTS )
  568.         return( ( FON_PTR )NULL );
  569.  
  570.     /* Go looking for an open space in the arena */
  571.     i= 0;
  572.     while( ( i < MAX_FONTS) && ( !free_font[i]) ) { ++i; }
  573.     free_font[i] = FALSE;
  574.  
  575.     newfont = &font_arena[i];
  576.     FTYPE(newfont)   = flag; /* SPEEDO */
  577.     AFLAG( newfont ) = SFLAG( newfont ) = FALSE;
  578.     FNEXT( newfont ) = FPREV( newfont ) = ( FON_PTR )NULL;
  579.     SEL( newfont )   = FALSE;
  580.     return( newfont );
  581. }
  582.  
  583.  
  584.  
  585.  
  586.  
  587. #if 0
  588. /* alpha_bit_add()
  589.  * ====================================================================
  590.  *  Add a font name into the Bitmap font list alphabetically, using strcmp to
  591.  *  determine where the font should be added.
  592.  */
  593. void 
  594. alpha_bit_add( FON_PTR font )
  595. {
  596.         FON_PTR current = available_list;
  597.         
  598.     if( current == ( FON_PTR )NULL )    /* Add to bare list */
  599.     {
  600.       available_list      = font;
  601.       available_last      = font;
  602.       FNEXT( font ) = ( FON_PTR )NULL;
  603.       FPREV( font ) = ( FON_PTR )NULL;
  604.       return;
  605.     }
  606.  
  607.     while( current != ( FON_PTR )NULL )
  608.       current = FNEXT( current );    /* Advance */
  609.  
  610.     if( current == ( FON_PTR )NULL ) /* Add as last */
  611.     {
  612.       FNEXT( available_last ) = font;
  613.       FPREV( font )     = available_last;
  614.       FNEXT( font )     = ( FON_PTR )NULL;
  615.       available_last    = font;
  616.       return;
  617.     }
  618. }
  619. #endif
  620.  
  621.  
  622.  
  623. /* Delete_Font()
  624.  * ====================================================================
  625.  * Delete a font simply by removing it from the active list.
  626.  * THIS is ONLY used when we are reading in the fonts from the
  627.  * SYS files.
  628.  */
  629. void
  630. Delete_Font( FON_PTR nodeptr )
  631. {
  632.    int i;
  633.    FON_PTR ptr;
  634.  
  635.    for( i = 0; i < MAX_FONTS; i++ )
  636.    {
  637.        ptr = &font_arena[i];
  638.        if( nodeptr == ptr )
  639.        {
  640.            free_font[ i ] = TRUE;    /* make it not in use. */
  641.            break;
  642.        }
  643.    }
  644. }
  645.  
  646.  
  647.  
  648. /* find_font_in_arena()
  649.  * ====================================================================
  650.  *  Given the user's string, attempt to match it to an existing font.
  651.  *  If matched successfully, return a pointer to the font's structure.
  652.  * NOTE: Used only when reading in the SYS files.
  653.  * This compares it by going through the arena, not the linked list.
  654.  * NULL - IT is a Font, but its not in the list.
  655.  * -1   - It is NOT a font
  656.  */
  657. FON_PTR 
  658. find_font_in_arena( char *userstring, char *extension )
  659. {
  660.     FON_PTR search;
  661.     int i, comp;
  662.     char *ptr;
  663.     char no_ext[15];
  664.  
  665.     /* copies 12 characters from the user's string into
  666.      * the local buffer. Finds the .FNT extension and
  667.      * and puts a null there. If it DOESN't find a .FNT,
  668.      * put a NULL at the beginning of the string.
  669.      */
  670.      for( i = 0; i < 12; i++ )
  671.         no_ext[i] = userstring[i];
  672.      no_ext[12] = '\0';
  673.      ptr = strstr( no_ext, extension );
  674.  
  675.      if( !ptr )
  676.      {
  677.         no_ext[0] = '\0';
  678.         return( ( FON_PTR )NIL );
  679.      }   
  680.      else
  681.      {
  682.         ptr += 4; /* gets us to the end */
  683.         *ptr = '\0';
  684.      }
  685.         
  686.      
  687.     /* Run through the bitmap fonts list and find the font
  688.        we've just been passed.  If the font name is ever bigger
  689.        than the current search name, we have gone too far!
  690.      */
  691.      
  692.     for( i = 0; i < font_counter; ++i )
  693.     {
  694.        if( !free_font[i] )
  695.        {       
  696.          search = &font_arena[i];
  697.          comp = strcmp(  no_ext, FFNAME( search ) );
  698.          if( comp == 0 )
  699.          {
  700.             return( ( FON_PTR )search );
  701.          }
  702.        }  
  703.     }
  704.     return( FON_PTR )NULL;
  705. }
  706.  
  707.  
  708.  
  709.  
  710.  
  711. /* build_list()
  712.  * ====================================================================
  713.  * Build the active or inactive linked list depending on whether
  714.  * we're lookig for Active Fonts or Inactive Fonts.
  715.  * IN: type == ACTIVE | INACTIVE
  716.  * OUT: return a count of the # of that type font found.
  717.  */
  718. int
  719. build_list( FON_PTR *top_list, FON_PTR *top_last, int type )
  720. {
  721.    FON_PTR  curptr;
  722.    int      i     = 0;
  723.    int        count = 0;
  724.    
  725.    i = 0;
  726.    *top_list = ( FON_PTR )NULL;
  727.    *top_last = ( FON_PTR )NULL;
  728.    
  729.    while ((i < MAX_FONTS) && (!free_font[i]))
  730.    {
  731.        curptr = &font_arena[i];
  732.    
  733.        /* Look for ACTIVE Fonts and SEL() == TRUE
  734.         *                   OR
  735.         * Look for INACTIVE Fonts and !SEL()
  736.         */
  737.        if( ( ( type == ACTIVE ) && ( SEL( curptr ) ) ) ||
  738.            ( ( type == INACTIVE ) && ( !SEL( curptr ) ) )
  739.          )
  740.        {
  741.                 /* Clear the SELECTED in the dialog box flag */
  742.          alpha_font_add( top_list, top_last, curptr );
  743.          count++;
  744.        }
  745.        i++;   
  746.    }
  747.    return( count );
  748. }
  749.  
  750.  
  751.  
  752.  
  753. /* alpha_font_add()
  754.  * ====================================================================
  755.  *  Add a font name into the FSM font list alphabetically, using strcmp to
  756.  *  determine where the font should be added.
  757.  */
  758. void 
  759. alpha_font_add( FON_PTR *top_list, FON_PTR *top_last, FON_PTR font)
  760. {
  761.     FON_PTR current = *top_list;
  762.     FON_PTR temp;
  763.         
  764.     if( current == ( FON_PTR )NULL )  /* Add to bare list */
  765.     {
  766.        *top_list   = font;
  767.        *top_last   = font;
  768.        FNEXT(font) = (FON_PTR )NULL;
  769.        FPREV(font) = (FON_PTR )NULL;
  770.        return;
  771.     }
  772.  
  773.     while( ( current != ( FON_PTR )NULL ) &&
  774.            ( strcmp( FNAME( font ), FNAME( current ) ) >= 0 )
  775.          )
  776.     {
  777.       current = FNEXT( current );     /* Advance     */
  778.     }
  779.  
  780.     if( current == ( FON_PTR )NULL ) /* Add as last */
  781.     {
  782.       temp          = *top_last;
  783.       FNEXT( temp ) = font;
  784.       FPREV(font)   = *top_last;
  785.       FNEXT(font)   = (FON_PTR )NULL;
  786.       *top_last     = font;
  787.       return;
  788.     }
  789.  
  790.     FPREV(font)    = FPREV(current);  /* Take over prev        */
  791.     FPREV(current) = font;          /* prev becomes this one */
  792.     FNEXT(font)    = current;      /* next is current       */
  793.     
  794.     if( FPREV(font) != (FON_PTR )NULL )
  795.         FNEXT(FPREV(font)) = font;
  796.     
  797.     if (*top_list == current)    /* Insert as first */
  798.         *top_list = font;
  799. }
  800.  
  801.  
  802.  
  803. #if 0
  804. /* build_specific_list()
  805.  * ====================================================================
  806.  * Build a list of JUST one type of font. Whether its active or not.
  807.  * This is used, for example, in the printer dialog box to show
  808.  * ONLY Bitmap fonts.
  809.  * type == SPD_FONT or BITMAP_FONT
  810.  * OUT: return a count of the # of that type font found.
  811.  */
  812. int
  813. build_specific_list( FON_PTR *top_list, FON_PTR *top_last, int type )
  814. {
  815.    FON_PTR  curptr;
  816.    int      i     = 0;
  817.    int        count = 0;
  818.    
  819.    i = 0;
  820.    *top_list = ( FON_PTR )NULL;
  821.    *top_last = ( FON_PTR )NULL;
  822.    
  823.    while ((i < MAX_FONTS) && (!free_font[i]))
  824.    {
  825.        curptr = &font_arena[i];
  826.        if( FTYPE( curptr ) == type )
  827.        {
  828.                 /* Clear the SELECTED in the dialog box flag */
  829.          alpha_font_add( top_list, top_last, curptr );
  830.          count++;
  831.        }
  832.        i++;   
  833.    }
  834.    return( count );
  835. }
  836.  
  837.  
  838. /* BuildBitMapList()
  839.  * ====================================================================
  840.  * Build the active or inactive linked list depending on whether
  841.  * we're lookig for Active Fonts or Inactive Fonts.
  842.  * For BitMap Fonts ONLY...
  843.  * IN: type == ACTIVE | INACTIVE
  844.  * OUT: return a count of the # of that type font found.
  845.  */
  846. int
  847. BuildBitMapList( FON_PTR *top_list, FON_PTR *top_last, int type )
  848. {
  849.    FON_PTR  curptr;
  850.    int      i     = 0;
  851.    int        count = 0;
  852.    
  853.    i = 0;
  854.    *top_list = ( FON_PTR )NULL;
  855.    *top_last = ( FON_PTR )NULL;
  856.    
  857.    while ((i < MAX_FONTS) && (!free_font[i]))
  858.    {
  859.        curptr = &font_arena[i];
  860.    
  861.        /* Look for ACTIVE Fonts and SEL() == TRUE
  862.         *                   OR
  863.         * Look for INACTIVE Fonts and !SEL()
  864.         */
  865.        if( FTYPE( curptr ) == BITMAP_FONT )
  866.        {
  867.          if( ( ( type == ACTIVE ) && ( XFLAG( curptr ) ) ) ||
  868.              ( ( type == INACTIVE ) && ( !XFLAG( curptr ) ) )
  869.            )
  870.          {
  871.                 /* Clear the SELECTED in the dialog box flag */
  872.          alpha_font_add( top_list, top_last, curptr );
  873.          count++;
  874.          }
  875.        }    
  876.        i++;   
  877.    }
  878.    return( count );
  879. }
  880. #endif
  881.  
  882.  
  883.  
  884.  
  885. /* CountFonts
  886.  * ====================================================================
  887.  * Count the number of installed fonts or available fonts
  888.  * and also the type.
  889.  * BITMAP_FONT or SPD_FONT
  890.  */
  891. int
  892. CountFonts( FON_PTR head_list, int flag )
  893. {
  894.    FON_PTR curptr;
  895.    int     count;
  896.  
  897.    count = 0;
  898.    curptr = head_list;
  899.  
  900.    while( curptr )
  901.    {
  902.       if( FTYPE( curptr ) == flag )
  903.         count++;
  904.       curptr = FNEXT( curptr );
  905.    }
  906.    return( count );
  907. }
  908.  
  909.  
  910. /* CountSelectedFonts()
  911.  * ====================================================================
  912.  * Count the number of Selected Fonts of a specific type.
  913.  * BITMAP_FONT or SPD_FONT
  914.  */
  915. int
  916. CountSelectedFonts( FON_PTR head_list, int flag )
  917. {
  918.    FON_PTR curptr;
  919.    int     count;
  920.  
  921.    count = 0;
  922.    curptr = head_list;
  923.  
  924.    while( curptr )
  925.    {
  926.       if( FTYPE( curptr ) == flag )
  927.       {
  928.     if( AFLAG( curptr ) )
  929.            count++;
  930.       }
  931.       curptr = FNEXT( curptr );
  932.    }
  933.    return( count );
  934. }
  935.  
  936.  
  937.  
  938.  
  939.  
  940.  
  941. /* --------------------------------------------------------------------
  942.  * POINT SIZES HANDLING
  943.  * ====================================================================
  944.  
  945. /* set_font_pts()
  946.  * ====================================================================
  947.  *   Take a line of point sizes and place them into the font.
  948.  *   IN: Pointer to Arena Font.
  949.  *       Array of points.
  950.  */
  951. void
  952. set_font_pts( FON_PTR font, char points[])
  953. {
  954.     int  i   = 0;
  955.     int  k   = 0;
  956.     int  num = atoi( &points[0] );
  957.  
  958.     if( font == (FON_PTR )NULL )
  959.         return;
  960.  
  961.         if( num > MAX_FONT_SIZE )
  962.             num = MAX_FONT_SIZE;
  963.  
  964.     if( num < MIN_FONT_SIZE )
  965.         num = MIN_FONT_SIZE;
  966.  
  967.     /* Checks of the point size already exists */
  968.     i = 0;
  969.     while( ( i < MAX_POINTS ) && ( POINTS(font)[i]) )
  970.     {
  971.        if( POINTS(font)[i] == num )
  972.            break;
  973.        i++;
  974.     }
  975.     
  976.     /* Adds the new pointsize INTO the array. The above
  977.      * loop checked if it existed.
  978.      */
  979.     if( ( i < MAX_POINTS ) && ( POINTS(font)[i] != num ))
  980.         POINTS(font)[i] = num;
  981.         
  982.     /* must be non-zero to be used as a default
  983.      * AND there must be room in fsm_defaults to
  984.      * put a new font size in there.
  985.      */
  986.     k = 0;
  987.     while( ( k < MAX_POINTS ) && (POINTS(font)[i]))
  988.     {
  989.        /* if fsm_default slot is zero, put the font
  990.         * size here..
  991.         */
  992.        if( !Current.point_size[k] )
  993.            Current.point_size[k] = POINTS(font)[i];
  994.                
  995.        /* if font size already is in default, skip it*/
  996.        if( Current.point_size[k] == POINTS(font)[i] )
  997.            break;
  998.        k++;
  999.     }   
  1000. }
  1001.  
  1002.  
  1003. /* CheckForDefaultPointSizes()
  1004.  * ====================================================================
  1005.  */
  1006. void
  1007. CheckForDefaultPointSizes( void )
  1008. {
  1009.     int i;
  1010.     FON_PTR curptr;
  1011.     
  1012.     /* There can be NO ZERO point size, so if it is ZERO, 
  1013.      * we have NO point sizes at this point. This routine is
  1014.      * called AFTER we have parsed the extend.sys AND have
  1015.      * tried checking fonts.
  1016.      */
  1017.     i = 0;    
  1018.     while ((i < MAX_FONTS) && (!free_font[i]))
  1019.     {
  1020.        curptr = &font_arena[i];
  1021.  
  1022.        /* Look for OUtline fonts that have no point sizes.
  1023.         * If the first point size slot is ZERO, then we have no point
  1024.         * sizes.
  1025.         */
  1026.        if( ( FTYPE( curptr ) == SPD_FONT ) && ( !POINTS(curptr)[0] ))
  1027.        {
  1028.        POINTS( curptr )[0] = 10;    /* Default point sizes for InActive Fonts */
  1029.        }
  1030.        i++;   
  1031.     }
  1032.     
  1033. }
  1034.  
  1035.  
  1036.  
  1037. /* GetFontMin()
  1038.  * ====================================================================
  1039.  */
  1040. long
  1041. GetFontMin( void )
  1042. {
  1043.    FON_PTR  curptr;
  1044.    long     size;
  1045.    
  1046.    size = 0L;
  1047.    curptr = installed_list;
  1048.    while( curptr )
  1049.    {
  1050.       if( FTYPE( curptr ) == SPD_FONT )
  1051.           size += FBUFF_SIZE( curptr );
  1052.       curptr = FNEXT( curptr );
  1053.    }
  1054.    return( size );
  1055. }
  1056.  
  1057.  
  1058. /* GetCharMin()
  1059.  * ====================================================================
  1060.  */
  1061. long
  1062. GetCharMin( void )
  1063. {
  1064.    FON_PTR  curptr;
  1065.    long     size;
  1066.    
  1067.    size = 0L;
  1068.    curptr = installed_list;
  1069.    while( curptr )
  1070.    {
  1071.      if( FTYPE( curptr ) == SPD_FONT )
  1072.        size += CBUFF_SIZE( curptr );
  1073.        
  1074.      curptr = FNEXT( curptr );
  1075.    }
  1076.    return( size );
  1077. }
  1078.  
  1079.  
  1080.  
  1081. /* --------------------------------------------------------------------
  1082.  * WRITE EXTEND.SYS STUFF
  1083.  * ====================================================================
  1084.  */
  1085.  
  1086.  
  1087. /* fast_write_extend()
  1088.  * ====================================================================
  1089.  */
  1090. int
  1091. fast_write_extend( void )
  1092. {
  1093.   int out;
  1094.   
  1095.   MF_Save();
  1096.   out = write_extend();
  1097.   MF_Restore();
  1098.   return( out );
  1099. }
  1100.  
  1101.  
  1102.  
  1103. /* write_extend()
  1104.  * ====================================================================
  1105.  * Write out the 'EXTEND.SYS file over the old ( or nonexistent one ).
  1106.  */
  1107. int 
  1108. write_extend( void )
  1109. {
  1110.     FON_PTR curptr;
  1111.     int new_extend;
  1112.     char line_buf[80];
  1113.     long time;
  1114.     long i;
  1115.     int  error;
  1116.  
  1117.     olddma = Fgetdta();    
  1118.     Fsetdta( &newdma );        /* Point to OUR buffer */
  1119.     
  1120.     /* Now look for EXTEND.SYS and rename it to EXTEND.OLD */
  1121.     error = Fsfirst( ExtendPath, 0 );
  1122.     if( error == E_OK )
  1123.     {
  1124.        strcpy( line_buf, OldExtendPath );
  1125.        Fdelete( OldExtendPath );
  1126.        Frename( 0, ExtendPath, OldExtendPath );
  1127.     }
  1128.  
  1129.     if( ( new_extend = Fcreate( ExtendPath, 0 ) ) < 0 )
  1130.     {
  1131.       form_alert(1, alerte11 );
  1132.       return( 1 );
  1133.     }
  1134.  
  1135.     sprintf( line_buf, ";\r\n" );
  1136.     Fwrite( new_extend, ( long )strlen( line_buf), line_buf );
  1137.     sprintf( line_buf, etitle1 );
  1138.     Fwrite( new_extend, ( long )strlen( line_buf ), line_buf );
  1139.     time = Gettime();
  1140.     sprintf(line_buf, msg1, 
  1141.         (int )((time  >> 21) & 0x0F),
  1142.         (int )((time  >> 16) & 0x1F),
  1143.         (int )(((time >> 25) & 0x7F) + 1980),
  1144.         (int )((time  >> 11) & 0x1F),
  1145.         (int )((time  >> 5)  & 0x3F) );
  1146.     Fwrite(new_extend, (long )strlen(line_buf), line_buf);
  1147.     sprintf(line_buf, ";\r\n");
  1148.     Fwrite(new_extend, (long )strlen(line_buf), line_buf);
  1149.  
  1150.     /* Write the path to the fonts */
  1151.     sprintf(line_buf, "PATH = %s", Current.FontPath);
  1152.     for( i = strlen( line_buf ); i && line_buf[i] != '\\'; i-- );
  1153.     if( !i )
  1154.        strcat( line_buf, "\\" );
  1155.     strcat( line_buf, "\r\n" );   
  1156.     Fwrite(new_extend, (long )strlen(line_buf), line_buf);
  1157.  
  1158.     /* Write out how big the bitmap cache is gonna be */
  1159.     sprintf(line_buf, "BITCACHE = %ld\r\n", Current.BitMapCacheSize*1024L);
  1160.     Fwrite(new_extend, (long )strlen(line_buf), line_buf);
  1161.  
  1162.     /* Write out how big the outline fonts cache is gonna be */
  1163.     /* AND how to divide up the outline cache buffer     */
  1164.     sprintf(line_buf, "FSMCACHE = %ld,%d\r\n", Current.SpeedoCacheSize * 1024L, Current.speedo_percent );
  1165.     Fwrite(new_extend, (long )strlen(line_buf), line_buf);
  1166.  
  1167.     /* Write out if we pre-generate a width table */
  1168.     sprintf(line_buf, "WIDTHTABLES = %d\r\n", Current.Width );
  1169.     Fwrite(new_extend, (long )strlen(line_buf), line_buf);
  1170.  
  1171.     curptr = installed_list;
  1172.     while( curptr != (FON_PTR )NULL)
  1173.     {
  1174.        if (SEL( curptr))
  1175.        {
  1176.          if( FTYPE( curptr ) == SPD_FONT )
  1177.          {
  1178.             sprintf(line_buf, "FONT = %s\r\n", FFNAME(curptr));
  1179.             Fwrite(new_extend, (long )strlen(line_buf), line_buf);
  1180.  
  1181.             sprintf( line_buf, "POINTS =");
  1182.             Fwrite(new_extend, (long )strlen(line_buf), line_buf);
  1183.             write_pointsizes( curptr, new_extend);
  1184.             sprintf( line_buf, "\r\n");
  1185.             Fwrite(new_extend, (long )strlen(line_buf), line_buf);
  1186.          }   
  1187.        }
  1188.        curptr = FNEXT( curptr );
  1189.     }
  1190.  
  1191.     Fclose(new_extend);
  1192.     Fsetdta( olddma );        /* Point to OLD buffer */
  1193.     return( 0 );
  1194. }
  1195.  
  1196.  
  1197. /* write_pointsizes()
  1198.  * ====================================================================
  1199.  * Write out the point sizes into the 'EXTEND.SYS'
  1200.  */
  1201. void
  1202. write_pointsizes( FON_PTR font, int new_extend)
  1203. {
  1204.    int  i, idx;
  1205.    int  already_set;
  1206.    char linebuf[80];
  1207.  
  1208.    for( i = 0, already_set = 0; i < MAX_POINTS; ++i )
  1209.       already_set |= POINTS(font)[i];
  1210.  
  1211.    if( !already_set )
  1212.    {
  1213.       /* Write out default point sizes */
  1214.       for( i = 0; ( i < MAX_POINTS ) && ( Current.point_size[i] != 0 ); ++i )
  1215.       {
  1216.          if( i != 0 )
  1217.            sprintf( linebuf, ",%d", Current.point_size[i] );
  1218.          else
  1219.        sprintf( linebuf, "%d", Current.point_size[i] );
  1220.      Fwrite( new_extend, ( long )strlen( linebuf ), linebuf );
  1221.       }
  1222.    }
  1223.    else
  1224.    {
  1225.       /* Write out point sizes */
  1226.       for( i = 0, idx = 0; i < MAX_POINTS; ++i )
  1227.       {
  1228.          if( POINTS(font)[i] )
  1229.          {
  1230.           if( idx != 0 )
  1231.          sprintf( linebuf, ",%d", POINTS( font )[i] );
  1232.        else
  1233.          sprintf( linebuf, "%d", POINTS( font )[i] );
  1234.        Fwrite( new_extend, ( long )strlen( linebuf ), linebuf );
  1235.        ++idx;
  1236.      }
  1237.       }
  1238.    }
  1239. }
  1240.  
  1241.  
  1242.  
  1243.  
  1244.